
import * as photoInfoPage from '../../../basisInfo/photoInfo/photoInfo';
import * as umfToast from '../../../../utils/UmfToast';

const PageStates = {
    normal: {canModify: true},
    desploy: {canModify: false}
};

Page({
    data: {
        photoUrls: {},
        //照片展示信息
        photoData: {},
        //页面状态
        pageState: PageStates.normal
    },

    onLoad: function (options) {
        let photoInfoData = JSON.parse(options.photoInfoData);
        this.setData({
            pageState: PageStates[options.pageState],

            storeId: photoInfoData.storeId,
            payeeName: photoInfoData.payeeName,
            storeMan: photoInfoData.storeMan,
            storeType: photoInfoData.storeType,
            isAuthorize: photoInfoData.isAuthorize,
            photoUrls: {
                payeeCardPhotoFront: decodeURIComponent(photoInfoData.payeeCardPhotoFront),
                payeeCardPhotoCon: decodeURIComponent(photoInfoData.payeeCardPhotoCon),
                categoryCardPhotoFront: decodeURIComponent(photoInfoData.categoryCardPhotoFront),
                categoryCardPhotoCon: decodeURIComponent(photoInfoData.categoryCardPhotoCon),
                shopSignPhotoFront: decodeURIComponent(photoInfoData.shopSignPhotoFront),
                shopSignPhotoCon: decodeURIComponent(photoInfoData.shopSignPhotoCon),
                busiLicensePhoto: decodeURIComponent(photoInfoData.busiLicensePhoto),
                authCertPhoto: decodeURIComponent(photoInfoData.authCertPhoto)
            }
        });

        setTimeout(() => {
            this.setData({
                photoData: _getPhotoData(this.data.storeId, this.data.payeeName, this.data.storeMan, this.data.storeType, this.data.isAuthorize,  this.data.photoUrls)
            });
        }, 0);
    },

    tapAdd: function (ress) {
        let id = ress.currentTarget.id;
        photoInfoPage.tapAdd(this, id, this.data.photoData);
    },

    tapPhoto: function (ress) {
        let id = ress.currentTarget.id;
        photoInfoPage.tapPhoto(this, id, this.data.photoData);
    },

    tapError: function (ress) {
        let id = ress.currentTarget.id;
        photoInfoPage.tapError(this, id, this.data.photoData);
    },

    // onSubmit: function (ress) {
    //     photoInfoPage.tapNext(this.data.photoData, ()=> {
    //         //提交成功
    //         umfToast.showToast("修改照片信息成功");
    //         wx.navigateBack({
    //             delta: 1
    //         });
    //
    //     });
    // }
});

function _getPhotoData(busId, payeeName, busPerson, busType, isAuthorize, photoUrls) {
    let photoInfoData = new photoInfoPage.photoData().init(busId, payeeName, busPerson, busType, isAuthorize)
        .initUrls(photoUrls);
    // for (let index in photoInfoData.viewData) {
    //     let photoItem = photoInfoData.viewData[index];
    //     if (photoItem && result[photoItem.photoTag]) {
    //         photoItem.photoUrl = result[photoItem.photoTag];
    //         photoInfoData.updateViewData(photoItem);
    //     }
    // }
    return photoInfoData;
}